home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / joe014.zip / JOE014.TAZ / JOE014.tar / cruddy.c < prev    next >
C/C++ Source or Header  |  1992-01-23  |  3KB  |  176 lines

  1. /* Cruddy terminal interface - should be very portable though
  2.    Copyright (C) 1991 Joseph H. Allen
  3.  
  4. This file is part of JOE (Joe's Own Editor)
  5.  
  6. JOE is free software; you can redistribute it and/or modify it under the terms
  7. of the GNU General Public License as published by the Free Software
  8. Foundation; either version 1, or (at your option) any later version. 
  9.  
  10. JOE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE.  See the GNU General Public License for more details.  
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with JOE; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <stdio.h>
  19. #include <signal.h>
  20. #include "async.h"
  21.  
  22. int have=0;
  23.  
  24. eputs(s)
  25. char *s;
  26. {
  27. fputs(s,stdout);
  28. }
  29.  
  30. eputc(c)
  31. {
  32. putchar(c);
  33. }
  34.  
  35. void tsignal();
  36.  
  37. sigjoe()
  38. {
  39. signal(SIGHUP,tsignal);
  40. signal(SIGTERM,tsignal);
  41. signal(SIGQUIT,SIG_IGN);
  42. signal(SIGPIPE,SIG_IGN);
  43. signal(SIGINT,SIG_IGN);
  44. }
  45.  
  46. signorm()
  47. {
  48. signal(SIGHUP,SIG_DFL);
  49. signal(SIGTERM,SIG_DFL);
  50. signal(SIGQUIT,SIG_DFL);
  51. signal(SIGPIPE,SIG_DFL);
  52. signal(SIGINT,SIG_DFL);
  53. }
  54.  
  55. aopen()
  56. {
  57. fflush(stdout);
  58. system("/bin/stty raw -echo");
  59. }
  60.  
  61. aclose()
  62. {
  63. fflush(stdout);
  64. system("/bin/stty cooked echo");
  65. }
  66.  
  67. aflush()
  68. {
  69. }
  70.  
  71. unsigned char *take=0;
  72.  
  73. anext()
  74. {
  75. unsigned char c;
  76. if(take)
  77.  if(*take)
  78.   {
  79.   int c;
  80.   if(*take!='\\') return *take++;
  81.   ++take;
  82.   if(!*take) return '\\';
  83.   else if(*take=='r') c='\r';
  84.   else if(*take=='b') c=8;
  85.   else if(*take=='n') c=10;
  86.   else if(*take=='f') c=12;
  87.   else if(*take=='a') c=7;
  88.   else if(*take=='\"') c='\"';
  89.   else if(*take>='0' && *take<='7')
  90.         {
  91.         c= *take++-'0';
  92.         if(*take>='0' && *take<='7')
  93.          {
  94.          c=c*8+*take++-'0';
  95.          if(*take>='0' && *take<='7') c=c*8+*take++-'0';
  96.          }
  97.         --take;
  98.         }
  99.   else c= *take;
  100.   ++take;
  101.   return c;
  102.   }
  103.  else take=0;
  104. fflush(stdout);
  105. if(read(fileno(stdin),&c,1)<1) tsignal(0);
  106. if(record) macroadd(c);
  107. return c;
  108. }
  109.  
  110. getsize()
  111. {
  112. #ifdef TIOCGSIZE
  113. struct ttysize getit;
  114. #else
  115. #ifdef TIOCGWINSZ
  116. struct winsize getit;
  117. #else
  118. char *p;
  119. #endif
  120. #endif
  121. #ifdef TIOCGSIZE
  122. if(ioctl(fileno(stdout),TIOCGSIZE,&getit)!= -1)
  123.  {
  124.  if(getit.ts_lines>=3) height=getit.ts_lines;
  125.  if(getit.ts_cols>=2) width=getit.ts_cols;
  126.  }
  127. #else
  128. #ifdef TIOCGWINSZ
  129. if(ioctl(fileno(stdout),TIOCGWINSZ,&getit)!= -1)
  130.  {
  131.  if(getit.ws_row>=3) height=getit.ws_row;
  132.  if(getit.ws_col>=2) width=getit.ws_col;
  133.  }
  134. #else
  135. if(p=getenv("ROWS")) sscanf(p,"%d",&height);
  136. if(p=getenv("COLS")) sscanf(p,"%d",&width);
  137. if(height<3) height=24;
  138. if(width<2) width=80;
  139. #endif
  140. #endif
  141. }
  142.  
  143. termtype()
  144. {
  145. getsize();
  146. }
  147.  
  148. shell()
  149. {
  150. int x;
  151. char *s=(char *)getenv("SHELL");
  152. if(!s)
  153.  {
  154.  puts("\nSHELL variable not set");
  155.  return;
  156.  }
  157. eputs("\nYou are at the command shell.  Type 'exit' to continue editing\r\n");
  158. aclose();
  159. if(x=fork())
  160.  {
  161.  if(x!= -1) wait(0);
  162.  }
  163. else
  164.  {
  165.  signorm();
  166.  execl(s,s,0);
  167.  _exit(0);
  168.  }
  169. aopen();
  170. }
  171.  
  172. susp()
  173. {
  174. shell();
  175. }
  176.